package com.ebelter.seneo.ui.fragments.main;


import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.ebelter.btcomlib.models.db.products.seneo.SeneoUserinfos;
import com.ebelter.btcomlib.models.eventbus.CommonEventBus;
import com.ebelter.btcomlib.models.https.NetUtils;
import com.ebelter.btcomlib.models.https.interfaces.HttpResponse;
import com.ebelter.btcomlib.utils.NumUtils;
import com.ebelter.btcomlib.utils.StringUtils;
import com.ebelter.btcomlib.utils.ToastUtil;
import com.ebelter.btcomlib.utils.ViewUtils;
import com.ebelter.btcomlib.utils.log.LogUtils;
import com.ebelter.seneo.R;
import com.ebelter.seneo.adapters.EndlessRecyclerOnScrollListener;
import com.ebelter.seneo.adapters.TrendHLvAdapter;
import com.ebelter.seneo.beans.httpresponse.GetAverageResponse;
import com.ebelter.seneo.contants.IUserContant;
import com.ebelter.seneo.models.SeneoBTManager;
import com.ebelter.seneo.models.SeneoNet;
import com.ebelter.seneo.ui.activitys.SeneoHistoryListActivity;
import com.ebelter.seneo.ui.activitys.SeneoMainActivity;
import com.ebelter.seneo.ui.fragments.BaseFragment;
import com.ebelter.seneo.ui.views.HoriLineView;
import com.ebelter.seneo.utils.SeneoUtils;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

import static com.ebelter.btcomlib.models.https.IHttpRequestField.startIndex;
import static com.ebelter.seneo.adapters.TrendHLvAdapter.DAY;
import static com.ebelter.seneo.adapters.TrendHLvAdapter.MONTH;
import static com.ebelter.seneo.adapters.TrendHLvAdapter.WEEK;
import static com.ebelter.seneo.adapters.TrendHLvAdapter.avgAR;
import static com.ebelter.seneo.adapters.TrendHLvAdapter.avgMQ;
import static com.ebelter.seneo.adapters.TrendHLvAdapter.avgWeight;


//填写密码
public class Trend_Fragment extends BaseFragment  implements  View.OnClickListener {


    public static final String TAG = "Trend_Fragment";

    private static final int TOP_WEIGHT = 1;
    private static final int TOP_FAT = 2;
    private static final int TOP_MUSCLE = 3;

    private static final int BUTTOM_DAY = 4;
    private static final int BUTTOM_WEEK = 5;
    private static final int BUTTOM_MONTH = 6;


    private int currentDisplayType;//当前显示的产品类型
    private int currentDisplayTime;//当前显示的时间类型


    ImageView is_history;
    RelativeLayout trend_top_weight_rl;
    RelativeLayout trend_top_fat_rl;
    RelativeLayout trend_top_muscle_rl;

    View trend_line1;
    View trend_line2;
    View trend_line3;

    RelativeLayout trend_date_day_rl;
    RelativeLayout trend_date_week_rl;
    RelativeLayout trend_date_mon_rl;

    View trend_line4;
    View trend_line5;
    View trend_line6;

    TextView trend_unit_tv;



    RecyclerView trend_hlv;
    HoriLineView horiLineView;
    private TrendHLvAdapter trendHLvAdapter;


    TextView cb1_1_tv;
    TextView cb1_2_tv;
    TextView cb1_3_tv;

    TextView cb2_1_tv;
    TextView cb2_2_tv;
    TextView cb2_3_tv;

    private int DAY_START_INDEX; //天的分页查询索引
    private int WEEK_START_INDEX;//周的分页查询索引
    private int MONTH_START_INDEX;//月的分页查询索引

    private void FV() {
        is_history=findViewById(R.id.is_history);

        trend_line1=findViewById(R.id.trend_line1);
        trend_line2=findViewById(R.id.trend_line2);
        trend_line3=findViewById(R.id.trend_line3);
        trend_line4=findViewById(R.id.trend_line4);
        trend_line5=findViewById(R.id.trend_line5);
        trend_line6=findViewById(R.id.trend_line6);

        trend_top_weight_rl=findViewById(R.id.trend_top_weight_rl);
        trend_top_fat_rl=findViewById(R.id.trend_top_fat_rl);
        trend_top_muscle_rl=findViewById(R.id.trend_top_muscle_rl);

        trend_date_day_rl=findViewById(R.id.trend_date_day_rl);
        trend_date_week_rl=findViewById(R.id.trend_date_week_rl);
        trend_date_mon_rl=findViewById(R.id.trend_date_mon_rl);

        trend_unit_tv=findViewById(R.id.trend_unit_tv);
        trend_hlv=findViewById(R.id.trend_hlv);
        horiLineView=findViewById(R.id.horlineview);

        cb1_1_tv=findViewById(R.id.cb1_1_tv);
        cb1_2_tv=findViewById(R.id.cb1_2_tv);
        cb1_3_tv=findViewById(R.id.cb1_3_tv);

        cb2_1_tv=findViewById(R.id.cb2_1_tv);
        cb2_2_tv=findViewById(R.id.cb2_2_tv);
        cb2_3_tv=findViewById(R.id.cb2_3_tv);

    }

    @Override
    protected void setListener() {
        is_history.setOnClickListener(this);
        trend_top_weight_rl.setOnClickListener(this);
        trend_top_fat_rl.setOnClickListener(this);
        trend_top_muscle_rl.setOnClickListener(this);
        trend_date_day_rl.setOnClickListener(this);
        trend_date_week_rl.setOnClickListener(this);
        trend_date_mon_rl.setOnClickListener(this);
    }

    @Override
    protected int setLayoutResouceId() {
        return R.layout.m_trend_fly;
    }

    @Override
    protected void initView() {
        FV();

    }



    @Override
    protected void initData(Bundle arguments) {
        EventBus.getDefault().register(this);

      //  getStrs();

        initCharView();

        horiLineView.setDisplay(true);//设置横线为可以显示
        ViewUtils.displayView(horiLineView);

        currentDisplayType = TOP_WEIGHT;//
        currentDisplayTime = BUTTOM_DAY;

        setDisplayData(currentDisplayType);
        setDisplayData(currentDisplayTime);
        updateUnit();

        requestDisplayData(true,false);

    }

    //更新单位
    private void updateUnit() {

        int unit = SeneoUtils.getUnitModel();//0kg 1lb
        String unitS=(unit==0? IUserContant.IDIS.kg:IUserContant.IDIS.lb);

        if (currentDisplayType==TOP_WEIGHT){
        }else if (currentDisplayType==TOP_FAT){
            unitS=IUserContant.IDIS.unitfat;
        }else if (currentDisplayType==TOP_MUSCLE){
        }
        setUnitStr(unitS);

    }

    private void initCharView() {
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getActivity());
        linearLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
        trend_hlv.setLayoutManager(linearLayoutManager);
        trendHLvAdapter=new TrendHLvAdapter(getActivity());
        trend_hlv.setAdapter(trendHLvAdapter);
        int unit = SeneoUtils.getUnitModel();//0kg 1lb
        if (trendHLvAdapter!=null){trendHLvAdapter.setUnit(unit);}

        // 设置加载更多监听
        trend_hlv.addOnScrollListener(new EndlessRecyclerOnScrollListener() {
            @Override
            public void onLoadMore(boolean isSlidingToLeft) {
                // 加载更多
                LogUtils.i(TAG,"-----onLoadMore() isSlidingToLeft="+isSlidingToLeft);
                if (!isSlidingToLeft){
                    requestDisplayData(false,false);
                }
            }
        });


    }

    private long lastLoadMoreTime;
    private boolean isLoadingData;
    public void requestDisplayData(final boolean scroll2end,boolean isFrom0) {



        if (!NetUtils.available()){
            ToastUtil.show(R.string.Network_error);
            return;
        }
        if (isLoadingData){
            LogUtils.i(TAG,"正在加载数据，此次请求拒绝掉");
            return;
        }

        final SeneoUserinfos userinfos = getSeneoUserinfos();
        if (userinfos==null){
            LogUtils.i(TAG,"----userinfos == null 此次请求拒绝掉");
            return;
        }

        lastLoadMoreTime=System.currentTimeMillis();

        if (isFrom0){
            DAY_START_INDEX=0;
            WEEK_START_INDEX=0;
            MONTH_START_INDEX=0;
            if (trendHLvAdapter!=null){
                trendHLvAdapter.clearData();
                updateCb1Title1();
            }
        }

        LogUtils.i(TAG, "-------requestDisplayData()------currentDisplayTime = "+currentDisplayTime+"-------currentDisplayType = "+currentDisplayType);

        final int whichTime;//1天 2周 3月
        final int start_index;//开始索引
        if (currentDisplayTime==BUTTOM_DAY){
            whichTime=1;
            start_index=DAY_START_INDEX;
        }else if (currentDisplayTime==BUTTOM_WEEK){
            whichTime=2;
            start_index=WEEK_START_INDEX;
        }else if (currentDisplayTime==BUTTOM_MONTH){
            whichTime=3;
            start_index=MONTH_START_INDEX;
        }else {
            return;
        }
        isLoadingData=true;

        LogUtils.i(TAG, "-------currentDisplayTime2 = "+currentDisplayTime+"-------currentDisplayType = "+currentDisplayType);

        Map<String,Serializable> paramMap=new HashMap<>();
        paramMap.put("userId", userinfos.user_id);
        paramMap.put("startIndex", start_index);
        paramMap.put("pageSize", 20);

        SeneoNet.getIntance().getsAverageData(this, whichTime, paramMap, new HttpResponse<GetAverageResponse>() {
            @Override
            public void result(boolean isRequestSuccess, String requestDes, GetAverageResponse getAverageResponse,String s) {
                LogUtils.i(TAG,"---------------s = "+s);
                LogUtils.i(TAG,"---------------userId="+userinfos.user_id+"--startIndex="+startIndex+"--pageSize=2");
                if (isRequestSuccess){
                    if (getAverageResponse.resultCode==0){
                        LogUtils.i(TAG,"---------------getsAverageData请求成功--------------"+getAverageResponse);
                        if (getAverageResponse.getResultData()!=null&&getAverageResponse.getResultData().getData()!=null&&getAverageResponse.getResultData().getData().size()>0){

                            LogUtils.i(TAG,"---------------getsAverageData请求成功--------------whichTime="+whichTime+"--" +
                                    "-DAY_START_INDEX="+DAY_START_INDEX+"----WEEK_START_INDEX="+WEEK_START_INDEX+"----MONTH_START_INDEX="+MONTH_START_INDEX);

                            if (getAverageResponse.getResultData()!=null&&getAverageResponse.getResultData().getData()!=null&&getAverageResponse.getResultData().getData().size()>0){
                                if (whichTime==1){
                                    DAY_START_INDEX++;
                                }else if (whichTime==2){
                                    WEEK_START_INDEX++;
                                }else if (whichTime==3){
                                    MONTH_START_INDEX++;
                                }
                            }

                            displayData(getAverageResponse.getResultData(),whichTime,scroll2end);
                        }

                    }else {
                        LogUtils.i(TAG,"---------------getsAverageData请求失败-------原因-----"+getAverageResponse.resultMessage);
                    }
                }else {
                    LogUtils.i(TAG,"---------------getsAverageData请求失败--------------");
                }
                isLoadingData=false;
            }
        });


    }

    //显示数据 whichTime 1DAY 2WEEK 3MONTH
    private void displayData(final GetAverageResponse.ResultDataBean resultData,int whichTime,final boolean scroll2end) {
        LogUtils.i(TAG,"---displayData---A--whichTime = " + whichTime);
        if (resultData==null){
            return;
        }
        if (trendHLvAdapter!=null){
            trendHLvAdapter.addDatas(resultData.getData(),whichTime);//添加数据
            if (scroll2end){//是否滚动到最后
                ViewUtils.recyclerViewScrollToPosition(trend_hlv,trendHLvAdapter.getItemCount()-1);
            }
            displayTargetWeightLine();
            updateCb1Title1();
        }
    }

    //显示目标体重横线
    public void displayTargetWeightLine(){
        LogUtils.i(TAG,"---displayTargetWeightLine---A");
        if (horiLineView==null){
            return;
        }
        if (trendHLvAdapter!=null&&trendHLvAdapter.getCurrentDisplayType()==TrendHLvAdapter.avgWeight&&trendHLvAdapter.getItemCount()!=0){
            //说明trendHLvAdapter里面是有数据的
            horiLineView.setDisplay(true);//设置horiLineView为可显示
            float p = 0;
            String displayText="";
            trendHLvAdapter.calculator();//计算一遍trendHLvAdapter里面的最大值和最小值
            if (trendHLvAdapter.maxWeight<=0){
                p=0;
            }else {
                SeneoUserinfos userinfos = getSeneoUserinfos();
                if (userinfos!=null){
                    float targetWeight=userinfos.targetWeight;
                    p= targetWeight/trendHLvAdapter.maxWeight;
                    int unit = SeneoUtils.getUnitModel();
                    displayText= NumUtils.numBaoLiuWei1(SeneoUtils.adapterDataFloat(targetWeight,unit))+"";
                }

            }
            LogUtils.i(TAG,"---displayTargetWeightLine---D--p="+p+"---displayText="+displayText);
            horiLineView.setPercentage(p);
            if (p==0){
                horiLineView.setDisplay(false);
            }
            horiLineView.setDisplayText(displayText);
        }else {
            horiLineView.setDisplay(false);
        }
        horiLineView.show();
    }

    private void setHoriLineViewShow(boolean isShow){
        if (horiLineView!=null){
            horiLineView.setDisplay(isShow);
            horiLineView.show();
        }
    }

    //更新title1
    private void updateCb1Title1() {
        String title11="";
        String title21="";
        String title12="";
        String title22="";
        String title13="";
        int unit = SeneoUtils.getUnitModel();

        if (currentDisplayTime==BUTTOM_DAY){
            switch (currentDisplayType){
                case TOP_WEIGHT:
                    title11=avg_weight_day;
                    title21=change_weight;
                    title12=trendHLvAdapter!=null?NumUtils.numBaoLiuWei1(SeneoUtils.adapterDataFloat(trendHLvAdapter.getAvg(DAY,avgWeight),unit))+"":"";
                    title22=trendHLvAdapter!=null?trendHLvAdapter.getChangeStr(DAY,avgWeight):"";
                    title13=(unit==0?"kg":"lb");
                    break;
                case TOP_FAT:
                    title11=avg_bfp_day;
                    title21=change_bodyfat_percentage;
                    title12=trendHLvAdapter!=null?NumUtils.numBaoLiuWei1( trendHLvAdapter.getAvg(DAY,avgAR))+"":"";
                    title22=trendHLvAdapter!=null?trendHLvAdapter.getChangeStr(DAY,avgAR):"";
                    title13="%";
                    break;
                case TOP_MUSCLE:
                    title11=avg_mass_day;
                    title21= change_muscle_mass;
                    title12=trendHLvAdapter!=null?NumUtils.numBaoLiuWei1(SeneoUtils.adapterDataFloat(trendHLvAdapter.getAvg(DAY,avgMQ),unit))+"":"";
                    title22=trendHLvAdapter!=null?trendHLvAdapter.getChangeStr(DAY,avgMQ):"";
                    title13=(unit==0?"kg":"lb");
                    break;

            }

        }else if (currentDisplayTime==BUTTOM_WEEK){
            switch (currentDisplayType){
                case TOP_WEIGHT:
                    title11=avg_weight_week;
                    title21=change_weight;
                    title12=trendHLvAdapter!=null?NumUtils.numBaoLiuWei1(SeneoUtils.adapterDataFloat(trendHLvAdapter.getAvg(WEEK,avgWeight),unit))+"":"";
                    title22=trendHLvAdapter!=null?trendHLvAdapter.getChangeStr(WEEK,avgWeight):"";
                    title13=(unit==0?"kg":"lb");
                    break;
                case TOP_FAT:
                    title11=avg_bfp_week;
                    title21=change_bodyfat_percentage;
                    title12=trendHLvAdapter!=null?NumUtils.numBaoLiuWei1(trendHLvAdapter.getAvg(WEEK,avgAR))+"":"";
                    title22=trendHLvAdapter!=null?trendHLvAdapter.getChangeStr(WEEK,avgAR):"";
                    title13="%";
                    break;
                case TOP_MUSCLE:
                    title11=avg_mass_week;
                    title21=change_muscle_mass;
                    title12=trendHLvAdapter!=null?NumUtils.numBaoLiuWei1(SeneoUtils.adapterDataFloat(trendHLvAdapter.getAvg(WEEK,avgMQ),unit))+"":"";
                    title22=trendHLvAdapter!=null?trendHLvAdapter.getChangeStr(WEEK,avgMQ):"";
                    title13=(unit==0?"kg":"lb");
                    break;
            }

        }else if(currentDisplayTime==BUTTOM_MONTH){
            switch (currentDisplayType){
                case TOP_WEIGHT:
                    title11=avg_weight_month;
                    title21=change_weight;
                    title12=trendHLvAdapter!=null?NumUtils.numBaoLiuWei1(SeneoUtils.adapterDataFloat( trendHLvAdapter.getAvg(MONTH,avgWeight),unit))+"":"";
                    title22=trendHLvAdapter!=null?trendHLvAdapter.getChangeStr(MONTH,avgWeight):"";
                    title13=(unit==0?"kg":"lb");
                    break;
                case TOP_FAT:
                    title11=avg_bfp_month;
                    title21=change_bodyfat_percentage;
                    title12=trendHLvAdapter!=null?NumUtils.numBaoLiuWei1(trendHLvAdapter.getAvg(MONTH,avgAR))+"":"";
                    title22=trendHLvAdapter!=null?trendHLvAdapter.getChangeStr(MONTH,avgAR):"";
                    title13="%";
                    break;
                case TOP_MUSCLE:
                    title11=avg_mass_month;
                    title21=change_muscle_mass;
                    title12=trendHLvAdapter!=null?NumUtils.numBaoLiuWei1(SeneoUtils.adapterDataFloat( trendHLvAdapter.getAvg(MONTH,avgMQ),unit))+"":"";
                    title22=trendHLvAdapter!=null?trendHLvAdapter.getChangeStr(MONTH,avgMQ):"";
                    title13=(unit==0?"kg":"lb");
                    break;

            }

        }


        ViewUtils.setTextViewStr(cb1_1_tv,title11);
        ViewUtils.setTextViewStr(cb1_2_tv,title12);
        ViewUtils.setTextViewStr(cb1_3_tv,title13);

        ViewUtils.setTextViewStr(cb2_1_tv,title21);
        ViewUtils.setTextViewStr(cb2_2_tv,title22);
        ViewUtils.setTextViewStr(cb2_3_tv,title13);

        int count = (trendHLvAdapter!=null?trendHLvAdapter.getItemCount():0);
        if (count==0){
            ViewUtils.setTextViewStr(cb1_2_tv,Dash_Fragment.Non);
            ViewUtils.setTextViewStr(cb2_2_tv,Dash_Fragment.Non);
        }

    }


    private SeneoUserinfos getSeneoUserinfos(){
        if (getActivity()==null){
            return null;
        }
        SeneoBTManager seneoBTManager = ((SeneoMainActivity)getActivity()).getSeneoBTManager();
        if (seneoBTManager!=null){
            SeneoUserinfos currentUserinfos = seneoBTManager.getCurrentUserinfos();
            if (currentUserinfos==null){
                LogUtils.i(TAG,"---getSeneoUserinfos()-找不到用户信息");
            }else {
                return currentUserinfos;
            }
        }
        return null;
    }

    @Override
    public void onClick(View v) {

        switch (v.getId()){
            case R.id.trend_top_weight_rl:
                setDisplayData(TOP_WEIGHT);
                setHoriLineViewShow(true);
                break;
            case R.id.trend_top_fat_rl:
                setDisplayData(TOP_FAT);
                setHoriLineViewShow(false);
                break;
            case R.id.trend_top_muscle_rl:
                setDisplayData(TOP_MUSCLE);
                setHoriLineViewShow(false);
                break;
            case R.id.trend_date_day_rl:
                setDisplayData(BUTTOM_DAY);
                break;
            case R.id.trend_date_week_rl:
                setDisplayData(BUTTOM_WEEK);
                break;
            case R.id.trend_date_mon_rl:
                setDisplayData(BUTTOM_MONTH);
                break;
            case R.id.is_history:


                final SeneoUserinfos userinfos = getSeneoUserinfos();
                if (userinfos==null){
                    LogUtils.i(TAG,"----userinfos == null 此次请求拒绝掉");
                    return;
                }
                Intent intent = new Intent(getActivity(), SeneoHistoryListActivity.class);
                intent.putExtra(SeneoHistoryListActivity.Userid,userinfos.user_id);
               startActivity(intent);

              //  requestDisplayData(true,true);

                break;

        }
    }


    private void setDisplayData(int which){

        if (which==TOP_WEIGHT||which==TOP_FAT||which==TOP_MUSCLE){
            setTopItemUI(which);
            if (trendHLvAdapter!=null)trendHLvAdapter.setCurrentDisplayType(which);
        }else if (which==BUTTOM_DAY||which==BUTTOM_WEEK||which==BUTTOM_MONTH){
            setButtomItemUI(which);
            if (trendHLvAdapter!=null)trendHLvAdapter.setCurrentDisplayTimeType(which);
            requestDisplayData(true,true);
        }

        updateUnit();
        updateCb1Title1();

    }






    private void setTopItemUI(int topSelect){
        ViewUtils.hideView(trend_line1);
        ViewUtils.hideView(trend_line2);
        ViewUtils.hideView(trend_line3);
        if (topSelect==TOP_WEIGHT){
            ViewUtils.displayView(trend_line1);
        }else if (topSelect==TOP_FAT){
            ViewUtils.displayView(trend_line2);
        }else if (topSelect==TOP_MUSCLE){
            ViewUtils.displayView(trend_line3);
        }
        currentDisplayType=topSelect;
    }

    private void setButtomItemUI(int buttomSelect){
        ViewUtils.hideView(trend_line4);
        ViewUtils.hideView(trend_line5);
        ViewUtils.hideView(trend_line6);
        ViewUtils.setSelects(false,trend_date_day_rl,trend_date_week_rl,trend_date_mon_rl);

        if (buttomSelect==BUTTOM_DAY){
            ViewUtils.displayView(trend_line4);
            ViewUtils.setSelect(trend_date_day_rl,true);
        }else if (buttomSelect==BUTTOM_WEEK){
            ViewUtils.displayView(trend_line5);
            ViewUtils.setSelect(trend_date_week_rl,true);
        }else if (buttomSelect==BUTTOM_MONTH){
            ViewUtils.displayView(trend_line6);
            ViewUtils.setSelect(trend_date_mon_rl,true);
        }
        currentDisplayTime = buttomSelect;

    }



    //设置单位
    private void setUnitStr(String msg){
        ViewUtils.setTextViewStr(trend_unit_tv,msg);
    }




    private String avg_weight_day="Daily average weight";//日均体重
    private String avg_weight_week="Weekly average weight";//周均体重
    private String avg_weight_month="Monthly average weight";//月均体重
    private String avg_bfp_day="Daily average body fat";//日均脂肪
    private String avg_bfp_week="Weekly average body fat";//周均脂肪
    private String avg_bfp_month="Monthly average body fat";//月均脂肪
    private String avg_mass_day="Daily average muscle";//日均肌肉
    private String avg_mass_week="Weekly average muscle";//周均肌肉
    private String avg_mass_month="Monthly average muscle";//月均肌肉

    private String change_weight="Weight change";//体重变化
    private String change_bodyfat_percentage="Body Fat change";//脂肪率变化
    private String change_muscle_mass="Muscle mass change";//肌肉变化




    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onEventMainThread(CommonEventBus event) {
        if (!event.whichReceive.contains(TAG)) {
            return;
        }
        LogUtils.i(TAG, TAG+"--onEventMainThread接收到CommonEventBus信息--" + event.toString());
       if (event.cmd==IUserContant.ICMDS.UPDATE_UNIT_DISPLAY){
           int unit = SeneoUtils.getUnitModel();//0kg 1lb
           if (trendHLvAdapter!=null){trendHLvAdapter.setUnit(unit);}
           updateUnit();
           updateCb1Title1();
           displayTargetWeightLine();
        }else if (event.cmd==IUserContant.ICMDS.UPDATE_TARGET_WEIGHT){
           displayTargetWeightLine();
        }else if (event.cmd==IUserContant.ICMDS.REQUEST_TREND_DATA){
           LogUtils.i(TAG, TAG+"--onEventMainThread接收到CommonEventBus信息--重新拉取trend数据的指令");
           displayTargetWeightLine();
            requestDisplayData(true,true);
       }
    }


    @Override
    public void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this);
    }


}
